import { _decorator, Camera, Component, log, Node } from 'cc';
import { setNodePosX, setNodePosY } from '../../../../extensions/cocos-scaffold-3x/assets/common/Utils';
import { GameplayComponent } from '../GameplayComponent';
const { ccclass, property } = _decorator;

@ccclass('GpCamera')
export class GpCamera extends GameplayComponent {

    @property(Camera)
    camera: Camera = null;

    followTarget: Node = null

    setFollowTarget(node: Node) {
        this.followTarget = node
    }

    start() {

    }

    update(deltaTime: number) {
        if (this.followTarget) {
            setNodePosX(this.node, this.followTarget.position.x)
            setNodePosY(this.node, this.followTarget.position.y-1000)
            
        } else {
            const target = this.prop.gpWorld.entityMap.get(10000)
            if (target) {
                this.setFollowTarget(target.node)
            }
        }
    }
}

